<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>上架商品</title>
    <th:block th:include="~{common/common::commonHead}"/>

</head>
<style>
    #goods{
        float:right;
        position: relative;
    }
</style>
<body data-width="850" data-height="560">
<form data-auto-set-value="edit" class="form-horizontal" data-get-url="goods/getGoods" role="form" th:action="@{/goodsPublish/addGoodsPublish}">
    <input type="hidden" id="goodsId" name="goodsId">
    <input type="hidden" id="goodsImg" name="goodsImg">
    <div class="col-xs-4">
        <div id="localImg" style="margin-left: 45px;">
            <img id="preview" th:src="@{/img/type/defaultGoodsImg.png}" width="300" height="300" style="display: block; width: 300px; height: 300px; margin: auto">
        </div>
        <div class="iconic-input right">
            <input type="file" name="file" id="doc" style="width:78px;height: 32px; opacity: 0; position: relative; margin-top: -30px; margin-left: 160px;" onchange="setImagePreview();">
        </div>
    </div>

    <div class="col-sm-6 col-xs-12" id="goods">
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 监所名称 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <select id="prisonsId" name="prisonsId" class="form-control spinner" data-url="org/listPrison" data-value-field="id" data-text-field="orgName" required >
                            <option value="">请选择监所</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 商品名称 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <input id="goodsName" name="goodsName" type="text" class="form-control spinner" placeholder="1~20位字符" required readonly maxlength="20">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 零售价 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <input id="goodsMarketPrice"  name="goodsMarketPrice" type="number" class="form-control spinner" placeholder="市场零售价格"
                               required data-valid-decimal="true" data-decimal="true" min="0.01" max="10000">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 供应价 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <input id="goodsSellPrice" name="goodsSellPrice" type="number" class="form-control spinner" placeholder="销售价格"
                               required data-valid-decimal="true" data-decimal="true" min="0.01" max="10000">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 结算价 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <input id="goodsSettlementPrice" name="goodsSettlementPrice" type="number" class="form-control spinner" placeholder="结算价格"
                               required data-valid-decimal="true" data-decimal="true" min="0.01" max="10000">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 商品单位 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <input id="goodsUnit" name="goodsUnit" type="text" class="form-control spinner" placeholder="1~60位字符"
                               required readonly maxlength="60">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 规格 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <input id="goodsSpec" name="goodsSpec" type="text" class="form-control spinner"  readonly maxlength="60" placeholder="1~60位字符">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 箱规 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <input id="boxSpec" name="boxSpec" type="text" class="form-control spinner" placeholder="1~60位字符"
                                readonly maxlength="60">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-md-2 col-sm-3 col-xs-4 control-label"> 商品类型 </label>
                <div class="col-md-6 col-sm-8 col-xs-8">
                    <div class="iconic-input right">
                        <select id="goodsType" name="goodsType" class="form-control" data-url="goods/listGoodsType" data-value-field="id" disabled required data-text-field="typeName"></select>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
</body>
</html>
<script>
    //下面用于图片上传预览功能
//    function setImagePreview() {
//        var docObj=document.getElementById("doc");
//        var formData = new FormData();
//        formData.append("files", docObj.files[0]);
//        $.ajax({
//            url: "file/upload",
//            type: "POST",
//            data: formData,
//            processData : false,// 告诉jQuery不要去处理发送的数据
//            contentType : false,// 告诉jQuery不要去设置Content-Type请求头
//            beforeSend:function(){
//                console.log("正在进行，请稍候");
//            },
//            success : function(data) {
//                if (data.code !== 0) {
//                    $.error(data.msg);
//                } else {
//                    console.log(data);
//                    var url = data.data[0].url;
//                    $("#goodsImg").val(url);
//                    $("#preview").attr("src", url);
//                }
//            },
//            error : function() {
//                $.error("上传失败");
//            }
//        });
//    }
    function afterAutoSetValue(data) {
        $("#preview").attr("src", data.goodsImg);
        $("#goodsId").val(data.id);
    }
    $(function(){
        var param = $.getUrlParams();
        $.doAjax("goods/getGoods",param,function(goods) {
//            $("#preview").attr("src","goods.goodsImg");
        })
    });
</script>
